#include<iostream>
#include<cstring>
#include<array>
using namespace std;

void handle_1() {
    cout << "What is your first name? ";
    char firstName[80];
    cin.getline(firstName, 80);
    cout << "What is your last name? ";
    char lastName[80];
    cin.getline(lastName, 80);
    cout << "What letter grade do you deserve? ";
    char grade;
    cin >> grade;
    grade += 1;
    cout << "What is your age? ";
    int age;
    cin >> age;
    cout << "Name: " << lastName << ", " << firstName << endl;
    cout << "Grade: " << grade << endl;
    cout << "Age: " << age << endl;
}

void handle_2() {
    string name;
    string dessert;
    cout << "Enter your name:\n";
    getline(cin, name);
    cout << "Enter your favorite dessert:\n";
    getline(cin, dessert);
    cout << "I have some delicious " << dessert;
    cout << " for you, " << name << endl;
}

void handle_3() {
    char firstname[80];
    char lastname[80];
    cout << "Enter your first name: ";
    cin.getline(firstname, 80);
    cout << "Enter your last name: ";
    cin.getline(lastname, 80);
    strcat_s(lastname, ", ");
    strcat_s(lastname, firstname);
    cout << "Here's the information in a single string: " << lastname << endl;
}

void hanele_4() {
    string lastname;
    string firstname;
    cout << "Enter your first name: ";
    getline(cin, firstname);
    cout << "Enter your last name: ";
    getline(cin, lastname);
    cout << "Here's the information in a single string: " << lastname + ", " + firstname << endl;
}

struct CandyBar
{
    string brand;
    float weight;
    int caloie;
};

void handle_5() {
    CandyBar snack{"Mocha Munch", 2.3, 350};
    cout << "The snack is :" << endl;
    cout << "Brand: " << snack.brand << endl;
    cout << "Weight: " << snack.weight << endl;
    cout << "Caloie: " << snack.caloie << endl;
}

void handle_6() {
    CandyBar list[3] = {
        {"snack1", 2.3, 123},
        {"snack2", 3.4, 333},
        {"snack3", 1.2, 321}
    };
    cout << "The snacks are: " << endl;
    for (int i = 0; i < 3; i++) {
        cout << "Brand: " << list[i].brand << endl;
        cout << "Weight: " << list[i].weight << endl;
        cout << "Caloie: " << list[i].caloie << endl;
        cout << endl;
    }
}

struct Pizza
{
    string brand;
    float diameter;
    float weight;
};

void handle_7() {
    Pizza p;
    cout << "Enter your pizza's information: " << endl;
    cout << "Brand: ";
    getline(cin, p.brand);
    cout << "Diameter: ";
    cin >> p.diameter;
    cout << "Weight: ";
    cin >> p.weight;
    cout << "Your pizza's information is: " << endl;
    cout << "Brand: " << p.brand << endl;
    cout << "Diameter: " << p.diameter << endl;
    cout << "Weight: " << p.weight << endl;
}

void handle_8() {
    Pizza *p = new Pizza;
    cout << "Enter your pizza's information: " << endl;
    cout << "Brand: ";
    getline(cin, p->brand);
    cout << "Diameter: ";
    cin >> p->diameter;
    cout << "Weight: ";
    cin >> p->weight;
    cout << "Your pizza's information is: " << endl;
    cout << "Brand: " << p->brand << endl;
    cout << "Diameter: " << p->diameter << endl;
    cout << "Weight: " << p->weight << endl;
    delete p;
}

void handle_9() {
    CandyBar* list = new CandyBar[3];
    list[0] = {"snack1", 2.3, 123};
    list[1] = {"snack2", 2.3, 123};
    list[2] = {"snack3", 2.3, 123};
    cout << "The snacks are: " << endl;
    for (int i = 0; i < 3; i++) {
        cout << "Brand: " << list[i].brand << endl;
        cout << "Weight: " << list[i].weight << endl;
        cout << "Caloie: " << list[i].caloie << endl;
        cout << endl;
    }
}

void handle_10() {
    const int number = 3;
    // array的元素个数不能是变量，必须是常量
    array<double, number> list;
    for (int i = 0; i < number; i++) {
        cout << "Enter the grade: ";
        cin >> list[i];
    }
    cout << "The grades are: " << list[0] << ", " << list[1] << ", " << list[2] << endl;
    cout << "The average grade is " << (list[0] + list[1] + list[2]) / 3 << endl;
}